//
//  MainViewController.m
//  QiYReader
//
//  Created by 奇阅科技 on 14/12/31.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "MainViewController.h"
#import "AppDelegate.h"
#import "ZMYLKDB.h"
@interface MainViewController ()
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl;
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView4;
@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toRecommendView:)];
    self.backgroundImageView4.userInteractionEnabled = YES;
    [self.backgroundImageView4 addGestureRecognizer:tap];
}
//-(void)viewDidLayoutSubviews
//{
//    [super viewDidLayoutSubviews];
//    self.scrollView.contentSize=CGSizeMake(SCREEN_WIDTH*4, APP_HEIGHT);
//    [self.scrollView layoutSubviews];
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    //    NSLog(@"%f",scrollView.contentOffset.x);
    //滑动停止时调用
    if (scrollView.contentOffset.x==0) {
        self.pageControl.currentPage=0;
    } else {
        if (scrollView.contentOffset.x==SCREEN_WIDTH) {
            self.pageControl.currentPage=1;
        } else {
            if (scrollView.contentOffset.x==SCREEN_WIDTH*2) {
                self.pageControl.currentPage=2;
            } else {
                if (scrollView.contentOffset.x==SCREEN_WIDTH*3) {
                    self.pageControl.currentPage=3;
                }
            }
        }
    }
}
- (void)toRecommendView:(id)sender {
    NSArray *booksArray = [NSMutableArray arrayWithArray:[[ZMYLKDB getLKDBHelper] getBookRack]];
    if (booksArray.count>0) {
        [AppDelegate delegate].window.rootViewController = [[UIStoryboard storyboardWithName:@"BookRack" bundle:Nil]instantiateInitialViewController];
    }else{
        [AppDelegate delegate].window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateInitialViewController];
    }
}

@end
